﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MShop.Core.Service.Context;
using MShop.Core.DataAccess;

 

namespace MShop.Core.Service.Search
{
    public class SearchDecorator<T> : AbstractContentItemServiceDecorator<T> where T:class,ISearchableContent,System.Data.Objects.DataClasses.IEntityWithKey
    {

        private readonly IObjectContextProvider Provider;
        private readonly ISearchService _searchService;
        public SearchDecorator(ISearchService searchService, IObjectContextProvider provider)
            : base(provider)
        {

            Provider = provider;
            _searchService = searchService;
        }

        public override void DeleteObject(T obj)
        {
            _searchService.DeleteContent(obj);
            base.DeleteObject(obj);
        }

        public override void SaveObject(T obj)
        {          
            base.SaveObject(obj);
            _searchService.AddContent(obj);
        }

        public override void UpdateObject(T obj)
        {
           base.UpdateObject(obj);
           _searchService.UpdateContent(obj);
        }
    }
}
